Binary Logarithm
   HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, the binary logarithm () is the
power Power most often refers to: * Power (physics), meaning "rate of doing work" ** Engine power, the power put out by an engine ** Electric power * Power (social and political), the ability to influence people or events ** Abusive power Power may a ...
to which the number must be raised to obtain the value . That is, for any real number , :x=\log_2 n \quad\Longleftrightarrow\quad 2^x=n. For example, the binary logarithm of is , the binary logarithm of is , the binary logarithm of is , and the binary logarithm of is . The binary logarithm is the
logarithm In mathematics, the logarithm is the inverse function to exponentiation. That means the logarithm of a number  to the base  is the exponent to which must be raised, to produce . For example, since , the ''logarithm base'' 10 o ...
to the base and is the
inverse function In mathematics, the inverse function of a function (also called the inverse of ) is a function that undoes the operation of . The inverse of exists if and only if is bijective, and if it exists, is denoted by f^ . For a function f\colon X ...
of the
power of two A power of two is a number of the form where is an integer, that is, the result of exponentiation with number two as the base and integer  as the exponent. In a context where only integers are considered, is restricted to non-negative ...
function. As well as , an alternative notation for the binary logarithm is (the notation preferred by ISO 31-11 and
ISO 80000-2 ISO 80000 or IEC 80000 is an international standard introducing the International System of Quantities (ISQ). It was developed and promulgated jointly by the International Organization for Standardization (ISO) and the International Electrotech ...
). Historically, the first application of binary logarithms was in
music theory Music theory is the study of the practices and possibilities of music. ''The Oxford Companion to Music'' describes three interrelated uses of the term "music theory". The first is the "rudiments", that are needed to understand music notation (ke ...
, by
Leonhard Euler Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in ma ...
: the binary logarithm of a frequency ratio of two musical tones gives the number of
octave In music, an octave ( la, octavus: eighth) or perfect octave (sometimes called the diapason) is the interval between one musical pitch and another with double its frequency. The octave relationship is a natural phenomenon that has been refer ...
s by which the tones differ. Binary logarithms can be used to calculate the length of the representation of a number in the binary numeral system, or the number of
bit The bit is the most basic unit of information in computing and digital communications. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represente ...
s needed to encode a message in information theory. In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, they count the number of steps needed for
binary search In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the m ...
and related algorithms. Other areas in which the binary logarithm is frequently used include combinatorics,
bioinformatics Bioinformatics () is an interdisciplinary field that develops methods and software tools for understanding biological data, in particular when the data sets are large and complex. As an interdisciplinary field of science, bioinformatics combi ...
, the design of sports
tournament A tournament is a competition involving at least three competitors, all participating in a sport or game. More specifically, the term may be used in either of two overlapping senses: # One or more competitions held at a single venue and concentr ...
s, and
photography Photography is the art, application, and practice of creating durable images by recording light, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film. It is employed ...
. Binary logarithms are included in the standard
C mathematical functions C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating-point numbers in one manner or another. Different C standards provide d ...
and other mathematical software packages. The integer part of a binary logarithm can be found using the
find first set In computer software and hardware, find first set (ffs) or find first one is a bit operation that, given an unsigned machine word, designates the index or position of the least significant bit set to one in the word counting from the least signifi ...
operation on an integer value, or by looking up the exponent of a
floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can b ...
value. The fractional part of the logarithm can be calculated efficiently.


History

The
powers of two A power of two is a number of the form where is an integer, that is, the result of exponentiation with number two as the base and integer  as the exponent. In a context where only integers are considered, is restricted to non-negative ...
have been known since antiquity; for instance, they appear in Euclid's ''Elements'', Props. IX.32 (on the
factorization In mathematics, factorization (or factorisation, see English spelling differences) or factoring consists of writing a number or another mathematical object as a product of several ''factors'', usually smaller or simpler objects of the same kind ...
of powers of two) and IX.36 (half of the
Euclid–Euler theorem The Euclid–Euler theorem is a theorem in number theory that relates perfect numbers to Mersenne primes. It states that an even number is perfect if and only if it has the form , where is a prime number. The theorem is named after mathematician ...
, on the structure of even
perfect number In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number. T ...
s). And the binary logarithm of a power of two is just its position in the ordered sequence of powers of two. On this basis,
Michael Stifel Michael Stifel or Styfel (1487 – April 19, 1567) was a German monk, Protestant reformer and mathematician. He was an Augustinian who became an early supporter of Martin Luther. He was later appointed professor of mathematics at Jena Universi ...
has been credited with publishing the first known table of binary logarithms in 1544. His book ''Arithmetica Integra'' contains several tables that show the
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
s with their corresponding powers of two. Reversing the rows of these tables allow them to be interpreted as tables of binary logarithms. Earlier than Stifel, the 8th century
Jain Jainism ( ), also known as Jain Dharma, is an Indian religion. Jainism traces its spiritual ideas and history through the succession of twenty-four tirthankaras (supreme preachers of ''Dharma''), with the first in the current time cycle being ...
mathematician
Virasena Acharya Virasena (792-853 CE), also known as Veerasena, was a Digambara monk and belonged to the lineage of Acharya Kundakunda. He was an Indian mathematician and Jain philosopher and scholar. He was also known as a famous orator and an accompl ...
is credited with a precursor to the binary logarithm. Virasena's concept of ''ardhacheda'' has been defined as the number of times a given number can be divided evenly by two. This definition gives rise to a function that coincides with the binary logarithm on the powers of two, but it is different for other integers, giving the 2-adic order rather than the logarithm. The modern form of a binary logarithm, applying to any number (not just powers of two) was considered explicitly by
Leonhard Euler Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in ma ...
in 1739. Euler established the application of binary logarithms to music theory, long before their applications in information theory and computer science became known. As part of his work in this area, Euler published a table of binary logarithms of the integers from 1 to 8, to seven decimal digits of accuracy.


Definition and properties

The binary logarithm function may be defined as the
inverse function In mathematics, the inverse function of a function (also called the inverse of ) is a function that undoes the operation of . The inverse of exists if and only if is bijective, and if it exists, is denoted by f^ . For a function f\colon X ...
to the
power of two A power of two is a number of the form where is an integer, that is, the result of exponentiation with number two as the base and integer  as the exponent. In a context where only integers are considered, is restricted to non-negative ...
function, which is a strictly increasing function over the positive
real number In mathematics, a real number is a number that can be used to measure a ''continuous'' one-dimensional quantity such as a distance, duration or temperature. Here, ''continuous'' means that values can have arbitrarily small variations. Every ...
s and therefore has a unique inverse. Alternatively, it may be defined as , where is the
natural logarithm The natural logarithm of a number is its logarithm to the base of the mathematical constant , which is an irrational and transcendental number approximately equal to . The natural logarithm of is generally written as , , or sometimes, if ...
, defined in any of its standard ways. Using the complex logarithm in this definition allows the binary logarithm to be extended to the
complex number In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form ...
s. As with other logarithms, the binary logarithm obeys the following equations, which can be used to simplify formulas that combine binary logarithms with multiplication or exponentiation: :\log_2 xy=\log_2 x + \log_2 y :\log_2\frac=\log_2 x - \log_2 y :\log_2 x^y = y\log_2 x. For more, see list of logarithmic identities.


Notation

In mathematics, the binary logarithm of a number is often written as . However, several other notations for this function have been used or proposed, especially in application areas. Some authors write the binary logarithm as ,. the notation listed in ''
The Chicago Manual of Style ''The Chicago Manual of Style'' (abbreviated in writing as ''CMOS'' or ''CMS'', or sometimes as ''Chicago'') is a style guide for American English published since 1906 by the University of Chicago Press. Its 17 editions have prescribed writi ...
''.
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist, mathematician, and professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of computer sc ...
credits this notation to a suggestion of Edward Reingold,
p. 11
The same notation was in the 1973 2nd edition of the same book (p. 23) but without the credit to Reingold.
but its use in both information theory and computer science dates to before Reingold was active. The binary logarithm has also been written as with a prior statement that the default base for the logarithm is . Another notation that is often used for the same function (especially in the German scientific literature) is ,. from
Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally a dialect spoken in the lower Tiber area (then known as Latium) around present-day Rome, but through the power of the ...
'' logarithmus dualis'' or ''logarithmus dyadis''. The , ISO 31-11 and
ISO 80000-2 ISO 80000 or IEC 80000 is an international standard introducing the International System of Quantities (ISQ). It was developed and promulgated jointly by the International Organization for Standardization (ISO) and the International Electrotech ...
standards recommend yet another notation, . According to these standards, should not be used for the binary logarithm, as it is instead reserved for the common logarithm .


Applications


Information theory

The number of digits (
bit The bit is the most basic unit of information in computing and digital communications. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represente ...
s) in the
binary representation A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: typically "0" (zero) and "1" (one). The base-2 numeral system is a positional notation ...
of a positive integer is the
integral part In mathematics and computer science, the floor function is the function that takes as input a real number , and gives as output the greatest integer less than or equal to , denoted or . Similarly, the ceiling function maps to the least int ...
of , i.e. : \lfloor \log_2 n\rfloor + 1. In information theory, the definition of the amount of
self-information In information theory, the information content, self-information, surprisal, or Shannon information is a basic quantity derived from the probability of a particular event occurring from a random variable. It can be thought of as an alternative ...
and
information entropy In information theory, the entropy of a random variable is the average level of "information", "surprise", or "uncertainty" inherent to the variable's possible outcomes. Given a discrete random variable X, which takes values in the alphabet \ ...
is often expressed with the binary logarithm, corresponding to making the bit the fundamental
unit of information In computing and telecommunications, a unit of information is the capacity of some standard data storage system or communication channel, used to measure the capacities of other systems and channels. In information theory, units of information a ...
. With these units, the
Shannon–Hartley theorem In information theory, the Shannon–Hartley theorem tells the maximum rate at which information can be transmitted over a communications channel of a specified bandwidth in the presence of noise. It is an application of the noisy-channel coding ...
expresses the information capacity of a channel as the binary logarithm of its signal-to-noise ratio, plus one. However, the
natural logarithm The natural logarithm of a number is its logarithm to the base of the mathematical constant , which is an irrational and transcendental number approximately equal to . The natural logarithm of is generally written as , , or sometimes, if ...
and the
nat Nat or NAT may refer to: Computing * Network address translation (NAT), in computer networking Organizations * National Actors Theatre, New York City, U.S. * National AIDS trust, a British charity * National Archives of Thailand * National As ...
are also used in alternative notations for these definitions.


Combinatorics

Although the natural logarithm is more important than the binary logarithm in many areas of pure mathematics such as
number theory Number theory (or arithmetic or higher arithmetic in older usage) is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic function, integer-valued functions. German mathematician Carl Friedrich Gauss (1777â ...
and
mathematical analysis Analysis is the branch of mathematics dealing with continuous functions, limit (mathematics), limits, and related theories, such as Derivative, differentiation, Integral, integration, measure (mathematics), measure, infinite sequences, series (m ...
, the binary logarithm has several applications in combinatorics: *Every binary tree with leaves has height at least , with equality when is a
power of two A power of two is a number of the form where is an integer, that is, the result of exponentiation with number two as the base and integer  as the exponent. In a context where only integers are considered, is restricted to non-negative ...
and the tree is a
complete binary tree In computer science, a binary tree is a k-ary k = 2 tree data structure in which each node has at most two children, which are referred to as the ' and the '. A recursive definition using just set theory notions is that a (non-empty) binary tr ...
. Relatedly, the
Strahler number In mathematics, the Strahler number or Horton–Strahler number of a mathematical tree is a numerical measure of its branching complexity. These numbers were first developed in hydrology by and ; in this application, they are referred to as the ...
of a river system with tributary streams is at most . *Every
family of sets In set theory and related branches of mathematics, a collection F of subsets of a given set S is called a family of subsets of S, or a family of sets over S. More generally, a collection of any sets whatsoever is called a family of sets, set fami ...
with different sets has at least elements in its union, with equality when the family is a
power set In mathematics, the power set (or powerset) of a set is the set of all subsets of , including the empty set and itself. In axiomatic set theory (as developed, for example, in the ZFC axioms), the existence of the power set of any set is po ...
. *Every
partial cube In graph theory, a partial cube is a graph that is isometric to a subgraph of a hypercube. In other words, a partial cube can be identified with a subgraph of a hypercube in such a way that the distance between any two vertices in the partial c ...
with vertices has isometric dimension at least , and has at most edges, with equality when the partial cube is a
hypercube graph In graph theory, the hypercube graph is the graph formed from the vertices and edges of an -dimensional hypercube. For instance, the cube graph is the graph formed by the 8 vertices and 12 edges of a three-dimensional cube. has vertices, e ...
. *According to
Ramsey's theorem In combinatorics, Ramsey's theorem, in one of its graph-theoretic forms, states that one will find monochromatic cliques in any edge labelling (with colours) of a sufficiently large complete graph. To demonstrate the theorem for two colours (say ...
, every -vertex
undirected graph In discrete mathematics, and more specifically in graph theory, a graph is a structure amounting to a set of objects in which some pairs of the objects are in some sense "related". The objects correspond to mathematical abstractions called '' v ...
has either a
clique A clique ( AusE, CanE, or ), in the social sciences, is a group of individuals who interact with one another and share similar interests. Interacting with cliques is part of normative social development regardless of gender, ethnicity, or popular ...
or an independent set of size logarithmic in . The precise size that can be guaranteed is not known, but the best bounds known on its size involve binary logarithms. In particular, all graphs have a clique or independent set of size at least and almost all graphs do not have a clique or independent set of size larger than . *From a mathematical analysis of the
Gilbert–Shannon–Reeds model In the mathematics of shuffling playing cards, the Gilbert–Shannon–Reeds model is a probability distribution on riffle shuffle permutations that has been reported to be a good match for experimentally observed outcomes of human shuffling, and th ...
of random shuffles, one can show that the number of times one needs to shuffle an -card deck of cards, using
riffle shuffle Shuffling is a procedure used to randomize a deck of playing cards to provide an element of chance in card games. Shuffling is often followed by a cut, to help ensure that the shuffler has not manipulated the outcome. __TOC__ Techniques Over ...
s, to get a distribution on permutations that is close to uniformly random, is approximately . This calculation forms the basis for a recommendation that 52-card decks should be shuffled seven times.


Computational complexity

The binary logarithm also frequently appears in the analysis of algorithms, not only because of the frequent use of binary number arithmetic in algorithms, but also because binary logarithms occur in the analysis of algorithms based on two-way branching. If a problem initially has choices for its solution, and each iteration of the algorithm reduces the number of choices by a factor of two, then the number of iterations needed to select a single choice is again the integral part of . This idea is used in the analysis of several
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
s and
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
s. For example, in
binary search In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the m ...
, the size of the problem to be solved is halved with each iteration, and therefore roughly iterations are needed to obtain a solution for a problem of size . Similarly, a perfectly balanced
binary search tree In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted binary tree data structure with the key of each internal node being greater than all the keys in the respective node's left subtree and ...
containing elements has height . The running time of an algorithm is usually expressed in big O notation, which is used to simplify expressions by omitting their constant factors and lower-order terms. Because logarithms in different bases differ from each other only by a constant factor, algorithms that run in time can also be said to run in, say, time. The base of the logarithm in expressions such as or is therefore not important and can be omitted. However, for logarithms that appear in the exponent of a time bound, the base of the logarithm cannot be omitted. For example, is not the same as because the former is equal to and the latter to . Algorithms with running time are sometimes called
linearithmic In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
. Some examples of algorithms with running time or are: * Average time quicksort and other comparison sort algorithms *Searching in balanced
binary search tree In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted binary tree data structure with the key of each internal node being greater than all the keys in the respective node's left subtree and ...
s *
Exponentiation by squaring Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
*
Longest increasing subsequence In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as possible. This subseq ...
Binary logarithms also occur in the exponents of the time bounds for some
divide and conquer algorithm In computer science, divide and conquer is an algorithm design paradigm. A divide-and-conquer algorithm recursively breaks down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved direc ...
s, such as the
Karatsuba algorithm The Karatsuba algorithm is a fast multiplication algorithm. It was discovered by Anatoly Karatsuba in 1960 and published in 1962. Knuth D.E. (1969) ''The Art of Computer Programming. v.2.'' Addison-Wesley Publ.Co., 724 pp. It is a div ...
for multiplying -bit numbers in time , and the Strassen algorithm for multiplying matrices in time . The occurrence of binary logarithms in these running times can be explained by reference to the master theorem for divide-and-conquer recurrences.


Bioinformatics

In
bioinformatics Bioinformatics () is an interdisciplinary field that develops methods and software tools for understanding biological data, in particular when the data sets are large and complex. As an interdisciplinary field of science, bioinformatics combi ...
, microarrays are used to measure how strongly different genes are expressed in a sample of biological material. Different rates of expression of a gene are often compared by using the binary logarithm of the ratio of expression rates: the log ratio of two expression rates is defined as the binary logarithm of the ratio of the two rates. Binary logarithms allow for a convenient comparison of expression rates: a doubled expression rate can be described by a log ratio of , a halved expression rate can be described by a log ratio of , and an unchanged expression rate can be described by a log ratio of zero, for instance. Data points obtained in this way are often visualized as a
scatterplot A scatter plot (also called a scatterplot, scatter graph, scatter chart, scattergram, or scatter diagram) is a type of plot or mathematical diagram using Cartesian coordinates to display values for typically two variables for a set of data ...
in which one or both of the coordinate axes are binary logarithms of intensity ratios, or in visualizations such as the
MA plot Within computational biology, an MA plot is an application of a Bland–Altman plot for visual representation of genomic data. The plot visualizes the differences between measurements taken in two samples, by transforming the data onto M (log ratio) ...
and
RA plot The ratio average (RA) plot is an integer-based version of an MA plot for visualizing two-condition count data. Its distinctive arrow-like shape derives from the way it includes condition-unique (0,''n'') or (''n'',0) points into the plot via an e ...
that rotate and scale these log ratio scatterplots.


Music theory

In
music theory Music theory is the study of the practices and possibilities of music. ''The Oxford Companion to Music'' describes three interrelated uses of the term "music theory". The first is the "rudiments", that are needed to understand music notation (ke ...
, the interval or perceptual difference between two tones is determined by the ratio of their frequencies. Intervals coming from
rational number In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ). The set of all ration ...
ratios with small numerators and denominators are perceived as particularly euphonious. The simplest and most important of these intervals is the
octave In music, an octave ( la, octavus: eighth) or perfect octave (sometimes called the diapason) is the interval between one musical pitch and another with double its frequency. The octave relationship is a natural phenomenon that has been refer ...
, a frequency ratio of . The number of octaves by which two tones differ is the binary logarithm of their frequency ratio.. To study
tuning system In music, there are two common meanings for tuning: * Tuning practice, the act of tuning an instrument or voice. * Tuning systems, the various systems of pitches used to tune an instrument, and their theoretical bases. Tuning practice Tun ...
s and other aspects of music theory that require finer distinctions between tones, it is helpful to have a measure of the size of an interval that is finer than an octave and is additive (as logarithms are) rather than multiplicative (as frequency ratios are). That is, if tones , , and form a rising sequence of tones, then the measure of the interval from to plus the measure of the interval from to should equal the measure of the interval from to . Such a measure is given by the cent, which divides the octave into equal intervals (
semitone A semitone, also called a half step or a half tone, is the smallest musical interval commonly used in Western tonal music, and it is considered the most dissonant when sounded harmonically. It is defined as the interval between two adjacent no ...
s of cents each). Mathematically, given tones with frequencies and , the number of cents in the interval from to is :\left, 1200\log_2\frac\. The
millioctave The millioctave (moct) is a unit of measurement for musical intervals. As is expected from the prefix milli-, a millioctave is defined as 1/1000 of an octave. From this it follows that one millioctave is equal to the ratio 21/1000, the 1000th root ...
is defined in the same way, but with a multiplier of instead of .


Sports scheduling

In competitive games and sports involving two players or teams in each game or match, the binary logarithm indicates the number of rounds necessary in a
single-elimination tournament A single-elimination, knockout, or sudden death tournament is a type of elimination tournament where the loser of each match-up is immediately eliminated from the tournament. Each winner will play another in the next round, until the final matc ...
required to determine a winner. For example, a tournament of players requires rounds to determine the winner, a tournament of teams requires rounds, etc. In this case, for players/teams where is not a power of 2, is rounded up since it is necessary to have at least one round in which not all remaining competitors play. For example, is approximately , which rounds up to , indicating that a tournament of teams requires rounds (either two teams sit out the first round, or one team sits out the second round). The same number of rounds is also necessary to determine a clear winner in a
Swiss-system tournament A Swiss-system tournament is a non-eliminating tournament format that features a fixed number of rounds of competition, but considerably fewer than for a round-robin tournament; thus each competitor (team or individual) does not play all the other ...
.


Photography

In
photography Photography is the art, application, and practice of creating durable images by recording light, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film. It is employed ...
,
exposure value In photography, exposure value (EV) is a number that represents a combination of a camera's shutter speed and f-number, such that all combinations that yield the same exposure have the same EV (for any fixed scene luminance). Exposure value is ...
s are measured in terms of the binary logarithm of the amount of light reaching the film or sensor, in accordance with the
Weber–Fechner law The Weber–Fechner laws are two related hypotheses in the field of psychophysics, known as Weber's law and Fechner's law. Both laws relate to human perception, more specifically the relation between the actual change in a physical stimulus an ...
describing a logarithmic response of the human visual system to light. A single stop of exposure is one unit on a base- logarithmic scale.. More precisely, the exposure value of a photograph is defined as :\log_2 \frac where is the
f-number In optics, the f-number of an optical system such as a camera lens is the ratio of the system's focal length to the diameter of the entrance pupil ("clear aperture").Smith, Warren ''Modern Optical Engineering'', 4th Ed., 2007 McGraw-Hill Pro ...
measuring the
aperture In optics, an aperture is a hole or an opening through which light travels. More specifically, the aperture and focal length of an optical system determine the cone angle of a bundle of rays that come to a focus in the image plane. An ...
of the lens during the exposure, and is the number of seconds of exposure. Binary logarithms (expressed as stops) are also used in
densitometry Densitometry is the quantitative measurement of optical density in light-sensitive materials, such as photographic paper or photographic film, due to exposure to light. Overview Optical density is a result of the darkness of a developed picture ...
, to express the
dynamic range Dynamic range (abbreviated DR, DNR, or DYR) is the ratio between the largest and smallest values that a certain quantity can assume. It is often used in the context of Signal (electrical engineering), signals, like sound and light. It is measured ...
of light-sensitive materials or digital sensors.


Calculation


Conversion from other bases

An easy way to calculate on
calculator An electronic calculator is typically a portable electronic device used to perform calculations, ranging from basic arithmetic to complex mathematics. The first solid-state electronic calculator was created in the early 1960s. Pocket-sized ...
s that do not have a function is to use the
natural logarithm The natural logarithm of a number is its logarithm to the base of the mathematical constant , which is an irrational and transcendental number approximately equal to . The natural logarithm of is generally written as , , or sometimes, if ...
() or the common logarithm ( or ) functions, which are found on most
scientific calculator A scientific calculator is an electronic calculator, either desktop or handheld, designed to perform mathematical operations. They have completely replaced slide rules and are used in both educational and professional settings. In some are ...
s. To change the logarithm base from or to one can use the
formulae In science, a formula is a concise way of expressing information symbolically, as in a mathematical formula or a ''chemical formula''. The informal use of the term ''formula'' in science refers to the general construct of a relationship betwee ...
: :\log_2 n = \frac = \frac, or approximately :\log_2 n \approx 1.442695\ln n \approx 3.321928\log_ n.


Integer rounding

The binary logarithm can be made into a function from integers and to integers by
rounding Rounding means replacing a number with an approximate value that has a shorter, simpler, or more explicit representation. For example, replacing $ with $, the fraction 312/937 with 1/3, or the expression with . Rounding is often done to ob ...
it up or down. These two forms of integer binary logarithm are related by this formula: : \lfloor \log_2(n) \rfloor = \lceil \log_2(n + 1) \rceil - 1, \textn \ge 1. The definition can be extended by defining \lfloor \log_2(0) \rfloor = -1. Extended in this way, this function is related to the number of leading zeros of the 32-bit unsigned binary representation of , . :\lfloor \log_2(n) \rfloor = 31 - \operatorname(n). The integer binary logarithm can be interpreted as the zero-based index of the most significant bit in the input. In this sense it is the complement of the
find first set In computer software and hardware, find first set (ffs) or find first one is a bit operation that, given an unsigned machine word, designates the index or position of the least significant bit set to one in the word counting from the least signifi ...
operation, which finds the index of the least significant bit. Many hardware platforms include support for finding the number of leading zeros, or equivalent operations, which can be used to quickly find the binary logarithm. The fls and flsl functions in the
Linux kernel The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
and in some versions of the
libc The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard. ISO/IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it was ...
software library also compute the binary logarithm (rounded up to an integer, plus one).


Iterative approximation

For a general positive real number, the binary logarithm may be computed in two parts.. First, one computes the
integer part In mathematics and computer science, the floor function is the function that takes as input a real number , and gives as output the greatest integer less than or equal to , denoted or . Similarly, the ceiling function maps to the least int ...
, \lfloor\log_2 x\rfloor (called the characteristic of the logarithm). This reduces the problem to one where the argument of the logarithm is in a restricted range, the interval , simplifying the second step of computing the fractional part (the mantissa of the logarithm). For any , there exists a unique integer such that , or equivalently . Now the integer part of the logarithm is simply , and the fractional part is . In other words: :\log_2 x = n + \log_2 y \quad\text y = 2^x \text y \in ,2) For normalized floating-point numbers, the integer part is given by the floating-point exponent, and for integers it can be determined by performing a count leading zeros operation.. The fractional part of the result is and can be computed iteratively, using only elementary multiplication and division. The algorithm for computing the fractional part can be described in pseudocode as follows: # Start with a real number in the half-open interval . If , then the algorithm is done, and the fractional part is zero. # Otherwise, square repeatedly until the result lies in the interval . Let be the number of squarings needed. That is, with chosen such that is in . # Taking the logarithm of both sides and doing some algebra: \begin \log_2 z &= 2^m \log_2 y \\ \log_2 y &= \frac \\ &= \frac \\ &= 2^ + 2^\log_2(z/2). \end # Once again is a real number in the interval . Return to step 1 and compute the binary logarithm of using the same method. The result of this is expressed by the following recursive formulas, in which m_i is the number of squarings required in the ''i''-th iteration of the algorithm: \begin \log_2 x &= n + 2^ \left( 1 + 2^ \left( 1 + 2^ \left( 1 + \cdots \right)\right)\right) \\ &= n + 2^ + 2^ + 2^ + \cdots \end In the special case where the fractional part in step 1 is found to be zero, this is a ''finite'' sequence terminating at some point. Otherwise, it is an
infinite series In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many quantities, one after the other, to a given starting quantity. The study of series is a major part of calculus and its generalization, math ...
that
converge Converge may refer to: * Converge (band), American hardcore punk band * Converge (Baptist denomination), American national evangelical Baptist body * Limit (mathematics) * Converge ICT, internet service provider in the Philippines *CONVERGE CFD s ...
s according to the
ratio test In mathematics, the ratio test is a test (or "criterion") for the convergence of a series :\sum_^\infty a_n, where each term is a real or complex number and is nonzero when is large. The test was first published by Jean le Rond d'Alembert a ...
, since each term is strictly less than the previous one (since every ). For practical use, this infinite series must be truncated to reach an approximate result. If the series is truncated after the -th term, then the error in the result is less than .


Software library support

The log2 function is included in the standard
C mathematical functions C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating-point numbers in one manner or another. Different C standards provide d ...
. The default version of this function takes
double precision Double-precision floating-point format (sometimes called FP64 or float64) is a floating-point number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point. Flo ...
arguments but variants of it allow the argument to be single-precision or to be a
long double In C and related programming languages, long double refers to a floating-point data type that is often more precise than double precision though the language standard only requires it to be at least as precise as double. As with C's other flo ...
. In computing environments supporting
complex numbers In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form a ...
and implicit type conversion such as
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation ...
the argument to the log2 function is allowed to be a negative number, returning a complex one..


References


External links

* *{{citation, url=http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog, title=Find the log base 2 of an N-bit integer in O(lg(N)) operations, work=Bit Twiddling Hacks, first=Sean Eron, last=Anderson, publisher=Stanford University, date=December 12, 2003, access-date=2015-11-25
Feynman and the Connection Machine
Binary arithmetic Calculus Logarithms